package cn.edu.csust.coursecard.controller;

import cn.edu.csust.coursecard.common.ReturnData;
import cn.edu.csust.coursecard.dao.dto.*;
import cn.edu.csust.coursecard.service.IParseHtmlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 解析前端获取到的html
 */
@RestController
@RequestMapping("parse")
public class ParseHtmlController {
    
    
    @Autowired
    private IParseHtmlService parseHtmlService;
    
    @PostMapping("/weekCourseHtml")
    public ReturnData parseWeekCourseHtml(@RequestParam("html") String weekCourseHtml){
    
        Course[][] courses = parseHtmlService.parseWeekCourseHtml(weekCourseHtml);
    
        return ReturnData.success(courses);
    }
    
    @PostMapping("/courseHtml")
    public ReturnData parseCourseHtml(@RequestParam("html") String courseHtml){
    
        WeekCourse[][] weekCourses = parseHtmlService.parseCourseHtml(courseHtml);
        
        return ReturnData.success(weekCourses);
    }
    
    @PostMapping("/ksapHtml")
    public ReturnData parseExamArrangement(@RequestParam("html") String examHtml){
    
        List<Exam> exams = parseHtmlService.parseExamArrangementHtml(examHtml);
    
        return ReturnData.success(exams);
    }
    
    @PostMapping("/scoreHtml")
    public ReturnData parseScoreHtml(@RequestParam("html") String scoreHtml){
    
        List<Score> scoreList = parseHtmlService.parseScoreHtml(scoreHtml);
        
        return ReturnData.success(scoreList);
    }
    
    @PostMapping("/pscjHtml")
    public ReturnData parseScoreDetailHtml(@RequestParam("html") String scoreDetailHtml){
    
        PscjInfo pscjInfo = parseHtmlService.parseScoreDetailHtml(scoreDetailHtml);
        
        return ReturnData.success(pscjInfo);
    }
    
    
}
